//
//  UIViewCellExtension.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/4.
//

import UIKit


extension UITableViewHeaderFooterView {
    static var identifier: String {
        return "\(self)"
    }
}

extension UITableViewCell {
    static var identifier: String {
        return "\(self)"
    }
    
    static func nib(_ nibNmae :String? = nil) -> UINib{
        return UINib(nibName: nibNmae ?? "\(self)", bundle: nil)
    }
}

extension UICollectionViewCell {
    static var identifier: String {
        return "\(self)"
    }
    
    static func nib(_ nibNmae :String? = nil) -> UINib{
        return UINib(nibName: nibNmae ?? "\(self)", bundle: nil)
    }
}

extension UIScrollView {
    // 解决有UIScrollView时不能在屏幕左边侧滑返回
    open override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        // 过滤UITextView（因为UITextView继承自UIScrollView），否则会引起崩溃
        if (gestureRecognizer.view?.isMember(of: UITextView.self))! {
            return true
        }
        let velocity = (gestureRecognizer as? UIPanGestureRecognizer)?.velocity(in: self)
        let location = gestureRecognizer.location(in: self)
        if (velocity?.x ?? 0 > 0.0 && Int(location.x) % Int(ScreenW) < 60) {
            return false
        }
        return true
    }
}
